package com.canbot.u05.activity.presidemode.newcode.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.canbot.u05.R;
import com.canbot.u05.utils.ToastTools;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class NHostEditnameDialog extends NHostBaseDialog {
    public static final int EDITNAME = 1;
    public static final int RENAME = 2;
    private int type = RENAME;
    @BindView(R.id.et_rename)
    EditText etRename;

    public NHostEditnameDialog(Context context, int type) {
        super(context);
        this.type = type;
        View view = LayoutInflater.from(this.getContext()).inflate(R.layout.nhost_rename_dialog, null);
        setContentView(view);
        ButterKnife.bind(this, view);
        setOnShowListener(v -> showKeyBoard(etRename));
        initData();
    }

    private static final String TAG = "NHostEditnameDialog";

    private void initData() {
        String hint = etRename.getHint().toString();
        Log.e(TAG, "initData: " + hint);
        if (type == RENAME) {
            etRename.setHint(R.string.rename);
        } else {
            etRename.setHint(R.string.inputName);
        }
    }


    @OnClick({R.id.btn_cancel, R.id.btn_normal})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_cancel:
                dismiss();
                break;
            case R.id.btn_normal:
                String rename = etRename.getText().toString();
                if (TextUtils.isEmpty(rename)) {
                    ToastTools.newInstance(getContext()).showText(getContext().getString(R.string.name_is_null));
                } else {
                    dismiss();
                    if (iDialogBtnLisenter != null) {
                        iDialogBtnLisenter.onConfirm(rename);
                    }
                }
                break;
        }
    }
}
